package service;

import entity.DataConstants;
import util.DatabaseUtils;

public class DatabaseManager {

	private static String DRIVER_CLASS = DataConstants.DRIVER_CLASS;
	private static String URL = DataConstants.URL;
	private static String USERNAME = DataConstants.USERNAME;
	private static String PASSWORD = DataConstants.PASSWORD;
	private static DatabaseUtils fwptDB;
	static {
		connectDB();
	}

	public static void connectDB() {
		try {
			fwptDB = new DatabaseUtils(DRIVER_CLASS, URL, USERNAME, PASSWORD, DataConstants.DM_FLAG);
		} catch (Exception e) {
			e.printStackTrace();
		}

		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				fwptDB.close();
			}
		});
	}
	
	public static DatabaseUtils getFWPTDB() {
		return fwptDB;
	}
	
}
